﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StoragePeriod.Common;
using StoragePeriod.Data;
using System.Web.Security;

namespace StoragePeriod.Web.Account
{
    public partial class ChangePassword : SecurityPage
    {
        public override string PrivCode()
        {
            return "fbf98fd0ad3c3dac";
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ChangePasswordPushButton_Click(object sender, EventArgs e)
        {
            var UserEntity = LinqUtility.LinqContext.SYS_Users.FirstOrDefault(p => p.UserCode == User.Identity.Name);
            string OldPwdMD5 = Utility.GetMD5PassWord(CurrentPassword.Text.Trim(), "");
            if (OldPwdMD5 != UserEntity.UserPWD || NewPassword.Text.Trim() != ConfirmNewPassword.Text.Trim())
            {
                Page.Alert("原始密码错误!");
                return;
            }
            string NewPwd = Utility.GetMD5PassWord(NewPassword.Text.Trim(), "");
            UserEntity.UserPWD = NewPwd;
            LinqUtility.LinqContext.SubmitChanges();

            FormsAuthentication.SignOut();
            Page.AlertAndClose("修改成功！请使用新密码重新登陆。");
        }
    }
}
